import matplotlib.pyplot as plt
import seaborn as sns
from scipy import stats
import numpy as np
group1 = [22, 25, 30, 28, 24]
group2 = [18, 20, 25, 22, 19]
t_stat, p_value = stats.ttest_ind(group1, group2, equal_var=True)  # 假设方差齐性
print(f"t_stat={t_stat}--p_value={p_value}")
# 绘制两组数据分布
sns.kdeplot(group1, label="Group 1")
sns.kdeplot(group2, label="Group 2")
plt.axvline(np.mean(group1), color='blue', linestyle='--')
plt.axvline(np.mean(group2), color='orange', linestyle='--')
plt.title("Independent t-test Visualization")
plt.legend()
plt.show()